<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>会员中心</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/csss.css">

    <link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/center.css">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">

</head>
<body>
<!--top-->
<ript>

    <!--导航-->
    <div class="dao_hang">
        <div class="nav_css">
            <!--右下侧广告-->
            <div class="advertisement" style="display:none">
                <h4>最新公告</h4>
                <div class="notice_new">
                </div>
            </div>
            <!--结束-->
            <div class="dao_list">
                <a href="__MODULE__/">首页</a>
            </div>
        </div>
    </div>
    <!--当前位置-->
    <div class="now_positionm">
        <span>当前位置：</span><a href="__MODULE__/">首页></a><a href="#">个人中心</a>
    </div>
    <!--centers-->
    <div class="centers_m">
        <!--清除浮动-->
        <div class="clear_sm"></div>
        <!--left-->
        <div class="centers_ml">
            <!--头像-->
            <div class="center_header">
                <a href="#"><img src="<?php  $a = session('member'); echo $a[0]['pic']; ?>"/></a>
                <em>您好，<font><?php  $a = session('member'); echo $a[0]['username']; ?></font></em>
            </div>
            <!--列表go-->
            <div class="centers_listm">
                <div class="centers_listm_one">
                    <img src="__PUBLIC__/home/imeags/zshy.png"/>
                    <em>会员中心</em>
                </div>

                <span class="gjszmdm">
                <a href="#" class="center_in_self"><font>信息资料</font></a>
            </span>
                <span class="gjszmdm">
                <a href="__MODULE__/Cart/cart" class="center_in_self"><font>购物车</font></a>
            </span>
                <span class="gjszmdm">
                <a href="__MODULE__/Personal/out" class="center_in_self"><font>退出登录</font></a>
            </span>
                <!--一条开始-->

            </div>
        </div>
        <!--right-->
        <div class="centers_mr">
            <h1 class="welcom_tm">欢迎您，超级会员 <font><?php  $a = session('member'); echo $a[0]['username']; ?></font>！您上次登录时间为
                2016-10-28 14:23</h1>
            <!--一条开始-->

            <div class="public_m1">

                <div class="public_m2">资料管理</div>
                <!--照片和内容-->
                <div class="zp_nrm">
                    <div class="zp_nrm_l">
                        <img src="<?php  $a = session('member'); echo $a[0]['pic']; ?>"/>
                        <a href="__MODULE__/Personal/personal/#pi">更换头像</a>
                    </div>
                    <!--right-->
                    <div class="zp_nrm_r">
                        <p><em>用户名：</em><i><?php  $a = session('member'); echo $a[0]['username']; ?></i></p>
                        <p><em>邮箱：</em><i>
                            <?php
                            $a = session('member');
                            if($a[0]['email'] == ''|| $a[0]['email'] == null){
                            echo '未绑定';
                           }else{
                             echo $a[0]['email'];
                            }?></i><a href="__MODULE__/Personal/personal/#em">立即设置</a></p>
                        <p><em>地址：</em><i>
                            <?php
                            $a = session('member');
                            if($a[0]['site'] == ''|| $a[0]['site'] == null){
                            echo '未绑定';
                           }else{
                             echo $a[0]['site'];
                            }?></i><a href="__MODULE__/Personal/personal/#si">立即设置</a></p>
                    </div>
                </div>
            </div>

            <div class="public_m1">
                <a name="em"></a>
                <div class="public_m2">绑定邮箱</div>
                <!--提示信息-->
                <div class="tip_notem">
                    <ul>
                        <li>1. 此邮箱将接收密码找回，订单通知等敏感性安全服务及提醒使用，请务必填写正确地址。</li>
                        <li>2. 设置提交后，系统将自动发送验证邮件到您绑定的信箱，您需在24小时内登录邮箱并完成验证。</li>
                        <li>3. 更改邮箱时，请通过安全验证后重新输入新邮箱地址绑定。</li>
                    </ul>
                </div>
                <div class="public_m4">
                    <p>
                        <em>绑定邮箱地址：</em>
                        <input type="text" style=" height:23px; border:1px solid #eaeaea; width:140px" name="email"
                               value=""><span id="email_msg"></span>
                    </p>
                    <a href="" id="email" class="public_m3">立即绑定</a>
                </div>
            </div>

            <div class="public_m1">
                <div class="public_m2">登录密码修改</div>
                <div class="public_m4">
                    <p>
                        <em>原密码：</em>
                        <input type="text" style=" height:23px; border:1px solid #eaeaea; width:140px"
                               name="password"><span id="paw_msg"></span>
                    </p>
                    <p>
                        <em>新的密码：</em>
                        <input type="text" style=" height:23px; border:1px solid #eaeaea; width:140px"
                               name="new_password"><span id="new_paw_msg"></span>
                    </p>
                    <p>
                        <em>确认密码：</em>
                        <input type="text" style=" height:23px; border:1px solid #eaeaea; width:140px "
                               name="new_confirm_password"><span id="new_confirm_paw_msg"></span>
                    </p>
                    <a href="" id="upPaw" class="public_m3">确认修改</a>
                </div>

            </div>
            <a name="si"></a>
            <div class="public_m1">
                <div class="public_m2">地址添加</div>
                <div class="public_m4">
                    <p>
                        <em>地址：</em>
                        <input type="text" style=" height:23px; border:1px solid #eaeaea; width:240px"
                               name="site"
                               value=""><span id="check_site" style="font-size: 14px;"></span>
                    </p>
                    <a href="" id="addSite" class="public_m3">确认修改</a>
                </div>
            </div>

            <a name="pi"></a>
            <div class="public_m1">
                <div class="public_m2">头像添加或修改</div>
                <div class="public_m4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">上传头像 </label>
                        <div class="layui-upload" style="margin-left: 110px;">
                            <div class="layui-upload-list" id="pic"></div>
                            <button type="button" class="layui-btn" id="upload">点击上传头像</button>
                            <a href="" id="addPic" class="public_m3">保存头像</a><span id="check_pic"></span>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</ript>
</body>
<script src="__PUBLIC__/home/js/jquery-1.11.0.min.js"></script>
<script src="__PUBLIC__/home/js/index2.js"></script>
<script src="__PUBLIC__/layui/layui.all.js"></script>
<script src="__PUBLIC__/home/js/personal.js"></script>
<script>
    $(function () {
        var data = {};
        $('#email').click(function () {
            data.email = $('input[name="email"]').val();
            // @TODO 验证邮箱
            if (data.email == '' || data.email == null) {
                $('#email_msg').html('<font color="red">您还未填写邮箱！</font>')
                return false;
            }
            $.post("{:U('Personal/checkEmail')}", data, function (ret) {
                // @TODO 发送绑定邮箱 ajax 请求
                if (ret.code == 1) {
                    $.post("{:U('Personal/addEmail')}", data, function (ret) {
                        if (ret.code == 1) {
                            alert('邮箱绑定成功！退出登录一下才会生效哦！');
                            history.go(0);
                            return false;
                        }
                        alert('邮箱绑定失败！');

                    })
                }
                $('#email_msg').html('<font color="red">该邮箱已经被绑定啦！</font>')
                return false;

            })
            return false;
        })
    })

    $(function () {
        var data = {};
        $('#upPaw').click(function () {
            data.password = $('input[name="password"]').val();
            data.new_password = $('input[name="new_password"]').val();
            data.new_confirm_password = $('input[name="new_confirm_password"]').val();
            // @TODO 验证原密码
            $.post("{:U('Personal/checkPaw')}", data, function (ret) {
                if (ret.code == 1) {
                    $('#paw_msg').html('<font color="red">密码不正确</font>');
                    return false;
                }
                // @TODO 验证新密码
                if (data.new_password == '' || data.new_password == null) {
                    $('#new_paw_msg').html('<font color="red">密码不能为空！</font>');
                    return false;
                }
                // @TODO 验证确认密码
                if (data.new_password !== data.new_confirm_password) {
                    $('#new_confirm_paw_msg').html('<font color="red">密码不一致！</font>');
                    return false;
                }
                // @TODO 发送修改密码 ajax请求
                $.post("{:U('Personal/upPaw')}", data, function (ret) {
                    if (ret.code == 1) {
                        alert('密码修改成功！退出登录一下才会生效哦！');
                        history.go(0);
                        return false;
                    }
                    alert('密码修改失败！');
                })
            })
            return false;
        })
    })

    $(function () {
        var data = {};
        $('#addSite').click(function () {
            data.site = $('input[name="site"]').val();
            // @TODO 验证地址
            if (data.site == '') {
                $('#check_site').html('<font color="red">请填写地址！</font>');
                return false;
            }
            // @TODO 发送修改地址 ajax 请求
            $.post("{:U('Personal/addSite')}", data, function (e) {
                if (e.code == 1) {
                    alert('地址添加成功！退出登录一下才会生效哦！');
                    history.go(0);
                    return false;
                }
                alert('地址添加失败！');
                return false;
            });
            return false;
        })
    })

    layui.use('upload', function () {
        var data = {};
        var $ = layui.jquery,
            upload = layui.upload;

        upload.render({
            elem: '#upload',
            url: "{:U('Personal/file')}",
            multiple: true,
            before: function (obj) {
                // @TODO 预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#pic').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
                });
            },
            done: function (res) {
                // @TODO 上传完毕 把图片地址添加到隐藏句中
                $('#pic').append('<input type="hidden" name="pic" value="' + res.data.fileName + '" />')
            }
        });
        $('#addPic').click(function () {
            data.pic = $('input[name="pic"]').val();
            // @TODO 验证图片
            if (data.pic == '' || data.pic == null) {
                $('#check_pic').html('<font color="red">你在逗我么！你还没有上传头像！</font>');
                return false;
            }
            $.post("{:U('Personal/addPic')}", data, function (e) {
                // @TODO 发送添加图片 ajax 请求
                if (e.code == 1) {
                    alert('保存成功！退出登录一下才会生效哦！');
                    history.go(0);
                    return false;
                }
                alert('保存失败！');
            })
            return false;
        })
    })

</script>
</html>    
            
